//
//  AboutUsViewController.m
//  MagicFang
//
//  Created by 华谕 on 2017/11/30.
//  Copyright © 2017年 HUAYU. All rights reserved.
//

#import "AboutUsViewController.h"
#import "helpMeViewController.h"

@interface AboutUsViewController ()
{
    UIWebView *webView;
}
@property (nonatomic, strong)NSString *phoneStr;

@end

@implementation AboutUsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self creatUI];
}

- (void)creatUI
{
    self.navigationController.navigationBar.translucent = NO;
    self.navigationItem.title = @"关于";
    self.view.backgroundColor = BacksColor;
    UIBarButtonItem *helpItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"bangzhuzhongxin"] style:UIBarButtonItemStylePlain target:self action:@selector(helpAction)];
    UIBarButtonItem *phoneItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"kefu"] style:UIBarButtonItemStylePlain target:self action:@selector(kefuAction)];
    NSArray *actionButtonItems = @[phoneItem,helpItem];
    self.navigationItem.rightBarButtonItems = actionButtonItems;
    webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-STA_NAV_HEIGHT)];
    [self.view addSubview:webView];
    [self getInstructions];
    [self getkefuPhone];
}

- (void)getInstructions
{
    WEAKSELF;
    [HYBaseHandler requestAboutUsParmers:nil Success:^(id obj) {
        if ([obj server_Getcodecheck])
        {
            NSString *html = obj[@"data"][@"propertyValue"];
            [webView loadHTMLString:html baseURL:nil];
            
        }
        else
        {
            [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
        }
    } failed:^(NSError *error) {
        
    }];
}

- (void)getkefuPhone
{
    WEAKSELF;
    [HYBaseHandler requestkefuPhoneParmers:nil Success:^(id obj) {
        if ([obj server_Getcodecheck])
        {
            weakSelf.phoneStr = obj[@"data"][@"propertyValue"];
        }
        else
        {
            [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
        }
    } failed:^(NSError *error) {
        
    }];
}

- (void)helpAction
{
    helpMeViewController *vc = [[helpMeViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
    
}

- (void)kefuAction
{
    if (_phoneStr.length > 0)
    {
        [[UIApplication sharedApplication]openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",_phoneStr]]];
    }
    else
    {
        [self getkefuPhone];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
